#!/bin/sh
#
# Install the Nu TextMate bundle from Jason Sallis' GitHub repository.
# Warning: This will remove any existing Nu.tmbundle.
#

BUNDLES_DIR="$HOME/Library/Application Support/TextMate/Bundles"
BUNDLE_NAME="Nu.tmbundle"
VERSION=`osascript -e 'tell application "TextMate" to version' | cut -d. -f1`

function getbundle () {
  git clone git://github.com/nulang/nu.tmbundle.git $BUNDLE_NAME
}

if [ $VERSION -eq 2 ]; then
  getbundle && open $BUNDLE_NAME
else
  rm -rf "$BUNDLES_DIR/$BUNDLE_NAME"
  mkdir -pv $BUNDLES_DIR
  cd $BUNDLES_DIR
  getbundle && osascript -e 'tell app "TextMate" to reload bundles'
fi
